/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
import {AsyncStorage} from 'react-native';
import {createStore, applyMiddleware} from 'redux';
import thunkMiddleware from 'redux-thunk';
import {persistStore, autoRehydrate} from 'redux-persist';
import createLogger from 'redux-logger';
import rootReducer from '../reducers/index';

const isDebuggingChrome = __DEV__&&!!window.navigator.userAgent;
const logger = createLogger({
    predicate:(getState,action) => isDebuggingChrome,
    collapsed:true,
    duration:true
});

var middlewares = applyMiddleware(thunkMiddleware,logger)(createStore);

export default function configureStore() {
    const store = autoRehydrate()(middlewares)(rootReducer);
    persistStore(store, {storage: AsyncStorage});
    if(isDebuggingChrome){
        window.store = store;
    }
    return store;
}